//
//  YCPedometerViewController.m
//  DemoPedometer
//
//  Created by 唐可雄 on 16/8/31.
//  Copyright © 2016年 swustyc. All rights reserved.
//

#import "YCPedometerViewController.h"

#import <CoreMotion/CoreMotion.h>

@interface YCPedometerViewController ()


@end

@implementation YCPedometerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    if (![CMPedometer isStepCountingAvailable]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"计步器不可用" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
    }
    
    CMPedometer *stepCounter = [[CMPedometer alloc] init];
    [stepCounter startPedometerUpdatesFromDate:[NSDate date] withHandler:^(CMPedometerData *pedometerData, NSError *error) {
        if (error)
            return;
        // 获取采样数据
        self.textView.text = [self.textView.text stringByAppendingString:[NSString stringWithFormat:@"%@\n", pedometerData.numberOfSteps]];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - IBAction

- (IBAction)clearBtnDidClick:(id)sender {
    self.textView.text = nil;
}

@end
